#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int n1 = n;
	int c;
	cin >> c;
	while (true) {
		int a1 = n % 10;
		int a2 = (n / 10) % 10;
		int a3 = (n / 100) % 10;
		int a4 = n / 1000;
		int sk[10] = { 0 };
		sk[a1] = 1;
		sk[a2] = 1;
		sk[a3] = 1;
		sk[a4] = 1;
		int c2 = 0;
		for (int i = 0; i < 10; i++)
		{
			if (sk[i] == 1)
				c2++;
		}
		if (c2 == c)
		{
			cout << n - n1 << " ";
			printf("%04d", n);
			break;
		}
		n++;
	}
	system("PAUSE");
	return 0;
}